﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using Newtonsoft.Json;
using BLL;

namespace TaoBaoProject.Handler.RegisterHandler
{
  /// <summary>
  /// GetShopHandler 的摘要说明
  /// </summary>
  public class GetShopHandler : IHttpHandler
  {

    public void ProcessRequest(HttpContext context)
    {
      context.Response.ContentType = "text/plain";

      IList<shop> shops = new List<shop>();

      ShopBLL shopBll = new ShopBLL();
      DataTable dt = shopBll.GetAllShops();
      shops.Add(new shop() { ShopID = "100000", ShopName = "选择店铺", ShopColor = "#000000" });

      for (int i = 0; i < dt.Rows.Count; i++)
      {
        shop p = new shop();
        p.ShopID = dt.Rows[i]["ShopID"].ToString();// "1";
        p.ShopName = dt.Rows[i]["ShopName"].ToString();// "一往情深";
        p.ShopColor = dt.Rows[i]["ShopColor"].ToString();
        shops.Add(p);
      }

      JsonSerializerSettings setting = new JsonSerializerSettings();
      setting.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
      string result = JsonConvert.SerializeObject(shops, Formatting.Indented, setting);
      context.Response.Write(result);
    }


    public bool IsReusable
    {
      get
      {
        return false;
      }
    }
  }


  public class shop
  {
    public string ShopID { get; set; }
    public string ShopName { get; set; }
    public string ShopColor { get; set; }
  }
}